import React from 'react';
import Sider from '@components/sider';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import _ from 'lodash';

const PersonalCenterSider = props => {
  const content = {
    title: '个人中心',
    body: [
      {
        icon: 'user-config',
        name: '帐号设置',
        to: '/personal-center/account-setting'
      }
    ]
  };
  if (
    Array.isArray(props.accessMap['personal|message']) &&
    props.accessMap['personal|message'].includes('view')
  ) {
    content.body.push({
      icon: 'notify-config',
      name: '消息设置',
      to: '/personal-center/message-setting'
    });
  }
  //isAntdIcon用于判断传入的icon是一个蚂蚁组件图标还是svg
  return <Sider content={content} isAntdIcon={true} />;
};

PersonalCenterSider.propTypes = {
  accessMap: PropTypes.object
};

const mapStateToProps = state => {
  return {
    accessMap: _.get(state, 'auth.user.accessMap', {})
  };
};

export default connect(
  mapStateToProps,
  null
)(PersonalCenterSider);
